package com.jb.faces;

import com.jb.util.ClassUtil;

import java.util.HashMap;
import java.util.Map;


public class FactoryFinder {
    public static String RENDER_KIT_FACTORY = "RENDER_KIT_FACTORY";
    public static String APPLICATION_FACTORY = "APPLICATION_FACTORY";
    public static String FACES_CONTEXT_FACTORY = "FACES_CONTEXT_FACTORY";
    public static String LIFECYCLE_FACTORY = "LIFECYCLE_FACTORY";
    static Map map = new HashMap();

    public static void setFactory(String key, String value) {
        map.put(key, value);
    }
    /**
     * Obtains the factory of a given type
     * @param factoryName name of the factory.
     * @return factory object if exists, or null.
     */
    public static Object getFactory(String factoryName) {
        String className = (String) map.get(factoryName);
        if(className!=null)
            return ClassUtil.createInstance(className);
        else
            return null;
    }

    public static void releaseFactories() {
        //
    }
}
